// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------
// Modification history:
// feature: listener code decoupling
// feature: change E2E packet format
// feature: add fast heartbeat feature
// feature: E2E New Requirement Development
// feature: support multiple sending based on topic
// ------------------------------------------------------------------

#ifndef INCLUDE_EDDS_RTPS_ATTRIBUTES_WRITERATTRIBUTES_H_
#define INCLUDE_EDDS_RTPS_ATTRIBUTES_WRITERATTRIBUTES_H_

#include <edds/rtps/common/Time_t.h>
#include <edds/rtps/common/Guid.h>
#include <edds/rtps/attributes/EndpointAttributes.h>
#include <ertps/qos/QosPolicies.h>

#include <functional>

#include <edds/rtps/flowcontrol/FlowControllerConsts.hpp>
#include <ertps/utils/collections/ResourceLimitedContainerConfig.hpp>

#include <xmlparser/attributes/XMLWriterAttributes.h>
#include <deps/attributes/BaseWriterAttributes.h>

namespace evbs {
namespace ertps {
namespace rtps {

typedef enum RTPSWriterPublishMode : octet { SYNCHRONOUS_WRITER, ASYNCHRONOUS_WRITER } RTPSWriterPublishMode;

using WriterTimes = vbsutil::xmlparser::WriterTimes;

/**
 * Class WriterAttributes, defining the attributes of a RTPSWriter.
 * @ingroup RTPS_ATTRIBUTES_MODULE
 */
class WriterAttributes : public vbs::BaseWriterAttributes {
 public:
    WriterAttributes()
        : liveliness_kind(AUTOMATIC_LIVELINESS_QOS),
          liveliness_lease_duration(TIME_T_INFINITE_SECONDS, TIME_T_INFINITE_NANOSECONDS),
          liveliness_announcement_period(TIME_T_INFINITE_SECONDS, TIME_T_INFINITE_NANOSECONDS),
          mode(SYNCHRONOUS_WRITER),
          disable_heartbeat_piggyback(false),
          disable_positive_acks(false),
          keep_duration(TIME_T_INFINITE_SECONDS, TIME_T_INFINITE_NANOSECONDS),
          deadline(TIME_T_INFINITE_SECONDS, TIME_T_INFINITE_NANOSECONDS),
          enable_e2e_protection(false),
          needCheckEnableFlag(false),
          e2e_p04_min_data_length(0),
          e2e_p04_max_data_length(0),
          e2e_p04_max_delta_counter(10),
          is_send_multi(false),
          heartbeat_per_max_samples(0) {
        endpoint.endpointKind = WRITER;
        endpoint.durabilityKind = TRANSIENT_LOCAL;
        endpoint.reliabilityKind = BEST_EFFORT;
    }

    virtual ~WriterAttributes() {}

    //! Writer Times (only used for RELIABLE).
    WriterTimes times;

    //! Liveliness kind
    ertps::LivelinessQosPolicyKind liveliness_kind;

    //! Liveliness lease duration
    Duration_t liveliness_lease_duration;

    //! Liveliness announcement period
    Duration_t liveliness_announcement_period;

    //! Indicates if the Writer is synchronous or asynchronous
    RTPSWriterPublishMode mode;

    //! Disable the sending of heartbeat piggybacks.
    bool disable_heartbeat_piggyback;

    //! Define the allocation behaviour for matched-reader-dependent collections.
    ResourceLimitedContainerConfig matched_readers_allocation;

    //! Disable the sending of positive ACKs
    bool disable_positive_acks;

    //! Keep duration to keep a sample before considering it has been acked
    Duration_t keep_duration;

    Duration_t deadline;

    //! Enable the e2e protection
    bool enable_e2e_protection;
    bool needCheckEnableFlag;
    //! E2E Profile04
    uint16_t e2e_p04_min_data_length;
    uint16_t e2e_p04_max_data_length;
    uint16_t e2e_p04_max_delta_counter;

    //! Whether sending multiple copies is supported
    bool is_send_multi;

    const char* flow_controller_name = vbsutil::flowctlString::EDDS_FLOW_CONTROLLER_DEFAULT;

    int32_t heartbeat_per_max_samples = 0;
    //When unack sample counts exceeds high_watermark, change to fast heartbeat period.
    int32_t high_watermark = -1;
    //When unack sample counts fall below high_watermark, change to heartbeat period.
    int32_t low_watermark = -1;

    uint8_t trace_point_status = 0;
};

} /* namespace rtps */
} /* namespace ertps */
} /* namespace evbs */

#endif  // INCLUDE_EDDS_RTPS_ATTRIBUTES_WRITERATTRIBUTES_H_
